<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta charset="utf-8" />
		<title>Tables - Ace Admin</title>

		<meta name="description" content="Static &amp; Dynamic Tables" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />

		<!-- bootstrap & fontawesome -->
		<link rel="stylesheet" href="${pageContext.request.contextPath}/static/assets/css/bootstrap.min.css" />
		<link rel="stylesheet" href="${pageContext.request.contextPath}/static/assets/css/font-awesome.min.css" />

		<!-- page specific plugin styles -->

		<!-- text fonts -->
		<link rel="stylesheet" href="${pageContext.request.contextPath}/static/assets/css/ace-fonts.css" />

		<!-- ace styles -->
		<link rel="stylesheet" href="${pageContext.request.contextPath}/static/assets/css/ace.min.css" id="main-ace-style" />

		<!--[if lte IE 9]>
			<link rel="stylesheet" href="${pageContext.request.contextPath}/static/assets/css/ace-part2.min.css" />
		<![endif]-->
		<link rel="stylesheet" href="${pageContext.request.contextPath}/static/assets/css/ace-skins.min.css" />
		<link rel="stylesheet" href="${pageContext.request.contextPath}/static/assets/css/ace-rtl.min.css" />

		<!--[if lte IE 9]>
		  <link rel="stylesheet" href="${pageContext.request.contextPath}/static/assets/css/ace-ie.min.css" />
		<![endif]-->

		<!-- inline styles related to this page -->

		<!-- ace settings handler -->
		<script src="${pageContext.request.contextPath}/static/assets/js/ace-extra.min.js"></script>

		<!-- HTML5shiv and Respond.js for IE8 to support HTML5 elements and media queries -->

		<!--[if lte IE 8]>
		<script src="${pageContext.request.contextPath}/static/assets/js/html5shiv.min.js"></script>
		<script src="${pageContext.request.contextPath}/static/assets/js/respond.min.js"></script>
		<![endif]-->
	</head>

	<body>
						<div class="main-content" > 															
										 <table id="sample-table-1" class="table table-striped table-bordered table-hover">
											
										<%-- 	<tr>
												<td>
													<a href="changeLocale?localeType=en_US"><spring:message code="page.index.english" /></a>
												</td>
												<td>
													<a href="changeLocale?localeType=zh_CN"><spring:message code="page.index.chinese" /></a>
												</td>
											</tr> --%>
											
											<tr>
												<td colspan="0">
												<button type="button" class="btn btn-primary add-User">
													<span class="glyphicon glyphicon-user"></span> 
													<spring:message code="page.index.add" />
												</button>
												</td>
												<td colspan="-5">
												<button type="button" class="btn btn-primary uploadFile-User">
													<span class="glyphicon glyphicon-user"></span> 
													<spring:message code="page.index.batch" />
												</button>
												</td>
											</tr>
											
												<tr>
													<th class="center">
														<label class="position-relative">
															<input type="checkbox" class="ace" />
															<span class="lbl"></span>
														</label>
													</th>
													<th><spring:message code="user.id.message" /></th>
													<th><spring:message code="user.name.message" /></th>		
													<th><spring:message code="user.gender.message" /></th>
													<th><spring:message code="user.tel.message" /></th>
													<th><spring:message code="user.email.message" /></th>
													<th><spring:message code="user.address.message" /></th>
													<th><spring:message code="user.birthday.message" /></th>
													<th>
														<spring:message code="user.action.message" />
													</th>

										
												</tr>
											

							<tbody>
								<c:forEach items="${userList }" var="user">
										<tr>
											<td class="center">
												<label class="position-relative">
												<input type="checkbox" class="ace" />
												<span class="lbl"></span>
												</label>
											</td>
											<td>${user.userId }</td>
											<td>${user.userName }</td>
											<td>${user.gender }</td>
											<td>${user.tel }</td>
											<td>${user.email }</td>
											<td>${user.address }</td>
											<td>${user.birthday }</td>
											<td>
												<button class="btn btn-xs btn-info edit-User">
													<i class="ace-icon fa fa-pencil bigger-120 "></i>
												</button>

												<button class="btn btn-xs btn-danger delete-User">
													<i class="ace-icon fa fa-trash-o bigger-120"></i>
												</button>							
											</td>										
										</tr>
									</c:forEach>															
										</table>
								</div>
								
								
	<!-- 添加试题-模态框(Modal) -->
	<div class="modal fade" id="addUserModel" tabindex="-1" role="dialog"
		aria-labelledby="addUserModalLabel">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="model-title" id="addUserModalLabel">添加试题</h4>
				</div>
				<div class="modal-body">
					<form id="addUserForm" method="post">
						
					    <p>
							<label>学号:&nbsp;&nbsp;</label><input type="text" name="userId"
								placeholder="填写学号" />
						</p>
						<p>
							<label>姓名:&nbsp;&nbsp;</label><input type="text" name="userName"
								placeholder="填写姓名" />
						</p>
						<p>
							<label>性别:&nbsp;&nbsp;</label><input type="text"  name="gender"
								placeholder="填写性别" />
						</p>
						<p>
							<label>联系电话:&nbsp;&nbsp;</label>
							<input type="text" name="tel" placeholder="填写手机" />
						</p>			
						<p>
							<label>电子邮箱:&nbsp;&nbsp;</label>
							<input type="text" name="email" placeholder="填写邮箱" />
						</p>
						<p>
							<label>联系地址:&nbsp;&nbsp;</label>
							<input type="text" name="address" placeholder="填写地址" />
						</p>
						<p>
							<label>出生日期:&nbsp;&nbsp;</label>
							<input type="text" name="birthday" placeholder="填写出生年月" />
						</p>
						
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button id="addUserSaveBtn" type="button" class="btn btn-primary">保存</button>
				</div>
			</div>
		</div>
	</div>   
								
	<!-- 修改试题-模态框(Modal) -->
	<div class="modal fade" id="editUserModel" tabindex="-1" role="dialog"
		aria-labelledby="editUserModalLabel">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="model-title" id="editUserModalLabel">修改用户信息</h4>
				</div>
				<div class="modal-body">
					<form id="editUserForm" method="post">
						 <p>	
							<input id="eduserId" type="hidden" name="userId" />
						</p>
						<p>
							<label>姓名:&nbsp;&nbsp;</label>
							<input id="eduserName" type="text" name="userName"/>
						</p>
						<p>
							<label>性别:&nbsp;&nbsp;</label>
							<input id="edgender" type="text"  name="gender"/>
						</p>
						<p>
							<label>联系电话:&nbsp;&nbsp;</label>
							<input id="edtel" type="text" name="tel"/>
						</p>			
						<p>
							<label>电子邮箱:&nbsp;&nbsp;</label>
							<input id="edemail" type="text" name="email"  />
						</p>
						<p>
							<label>联系地址:&nbsp;&nbsp;</label>
							<input id="edaddress" type="text" name="address"/>
						</p>
						<p>
							<label>出生日期:&nbsp;&nbsp;</label>
							<input id="edbirthday" type="text" name="birthday" />
						</p>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button id="editUserSaveBtn" type="button" class="btn btn-primary">保存</button>
				</div>
			</div>
		</div>
	</div>  	
	
	<!-- 批量上传试题-模态框(Modal) -->
	<div class="modal fade" id="uploadFileModel" tabindex="-1" role="dialog"
		aria-labelledby="uploadFileModalLabel">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="model-title" id="uploadFileModalLabel">上传</h4>
				</div>
				<div class="modal-body">
					<input id="uploadFile" name="uploadFile" type="file"/>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button id="uploadFileSaveBtn" type="button" class="btn btn-primary">保存</button>
				</div>
			</div>
		</div>
	</div>  									
							
		<!-- basic scripts -->

		<!--[if !IE]> -->
		<script type="text/javascript">
			window.jQuery || document.write("<script src='${pageContext.request.contextPath}/static/assets/js/jquery.min.js'>"+"<"+"/script>");
		</script>

		<!-- <![endif]-->

		<!--[if IE]>
<script type="text/javascript">
 window.jQuery || document.write("<script src='${pageContext.request.contextPath}/static/assets/js/jquery1x.min.js'>"+"<"+"/script>");
</script>
<![endif]-->
		<script type="text/javascript">
			if('ontouchstart' in document.documentElement) document.write("<script src='${pageContext.request.contextPath}/static/assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
		</script>
		<script src="${pageContext.request.contextPath}/static/assets/js/bootstrap.min.js"></script>

		<!-- page specific plugin scripts -->
		<script src="${pageContext.request.contextPath}/static/assets/js/jquery.dataTables.min.js"></script>
		<script src="${pageContext.request.contextPath}/static/assets/js/jquery.dataTables.bootstrap.js"></script>

		<!-- ace scripts -->
		<script src="${pageContext.request.contextPath}/static/assets/js/ace-elements.min.js"></script>
		<script src="${pageContext.request.contextPath}/static/assets/js/ace.min.js"></script>

		<!-- inline scripts related to this page -->
		<script type="text/javascript">
			jQuery(function($) {
				var oTable1 = 
				$('#sample-table-2')
				//.wrap("<div class='dataTables_borderWrap' />")   //if you are applying horizontal scrolling (sScrollX)
				.dataTable( {
					bAutoWidth: false,
					"aoColumns": [
					  { "bSortable": false },
					  null, null,null, null, null,
					  { "bSortable": false }
					],
					"aaSorting": [],
			
					//,
					//"sScrollY": "200px",
					//"bPaginate": false,
			
					//"sScrollX": "100%",
					//"sScrollXInner": "120%",
					//"bScrollCollapse": true,
					//Note: if you are applying horizontal scrolling (sScrollX) on a ".table-bordered"
					//you may want to wrap the table inside a "div.dataTables_borderWrap" element
			
					//"iDisplayLength": 50
			    } );
				/**
				var tableTools = new $.fn.dataTable.TableTools( oTable1, {
					"sSwfPath": "${pageContext.request.contextPath}/static/${pageContext.request.contextPath}/static/copy_csv_xls_pdf.swf",
			        "buttons": [
			            "copy",
			            "csv",
			            "xls",
						"pdf",
			            "print"
			        ]
			    } );
			    $( tableTools.fnContainer() ).insertBefore('#sample-table-2');
				*/
			
			
				$(document).on('click', 'th input:checkbox' , function(){
					var that = this;
					$(this).closest('table').find('tr > td:first-child input:checkbox')
					.each(function(){
						this.checked = that.checked;
						$(this).closest('tr').toggleClass('selected');
					});
				});
			
			
				$('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
				function tooltip_placement(context, source) {
					var $source = $(source);
					var $parent = $source.closest('table')
					var off1 = $parent.offset();
					var w1 = $parent.width();
			
					var off2 = $source.offset();
					//var w2 = $source.width();
			
					if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
					return 'left';
				}
			
			})
		</script>
		
		<script type="text/javascript">
			//触发添加摸态框
			$('.add-User').click(function(){
				$('#addUserModel').modal('show');	
			});
			
			//保存并添加试题
			$('#addUserSaveBtn').click(function(){
				/* if($('#addTestForm').valid()){ //前台校验 */
					
					var userId = $('#addUserForm input[name="userId"]').val();
					var userName = $('#addUserForm input[name="userName"]').val();
					var gender = $('#addUserForm input[name="gender"]').val();
					var tel = $('#addUserForm input[name="tel"]').val();
					var email = $('#addUserForm input[name="email"]').val();
					var address = $('#addUserForm input[name="address"]').val();
					var birthday = $('#addUserForm input[name="birthday"]').val();	
						
					$.ajax({ //通过后传到后台
						type: 'POST',
						url: '${contextPath}/OnlineExam/createUser',
						data: {
							userId: userId,
							userName: userName,
							gender: gender,
							tel: tel,
							email: email,
							address: address,
							birthday: birthday,
						},
						dataType: "json",
						success: function(data){
							//判断成功与否
							if(data.success){
								alert('添加成功');
								window.location.reload();
							}else{
					
								alert('添加失败！');
							}
						}
					});	
				//}
			});
			
			//触发修改摸态框
			$('.edit-User').click(function(){
				var userId = $(this).parent().siblings().eq(1).text();
				var userName = $(this).parent().siblings().eq(2).text();
				var gender = $(this).parent().siblings().eq(3).text();
				var tel = $(this).parent().siblings().eq(4).text();
				var email = $(this).parent().siblings().eq(5).text();
				var address = $(this).parent().siblings().eq(6).text();
				var birthday = $(this).parent().siblings().eq(7).text();
				
				$('#eduserId').val(userId);
				$('#eduserName').val(userName);
				$('#edgender').val(gender);
				$('#edtel').val(tel);
				$('#edemail').val(email);
				$('#edaddress').val(address);
				$('#edbirthday').val(birthday);
				
				$('#editUserModel').modal('show');	
			});
			
			//保存并修改试题
			$("#editUserSaveBtn").click(function(){
				var userId = $('#editUserForm input[name="userId"]').val();
				var userName = $('#editUserForm input[name="userName"]').val();
				var gender = $('#editUserForm input[name="gender"]').val();
				var tel = $('#editUserForm input[name="tel"]').val();
				var email = $('#editUserForm input[name="email"]').val();
				var address = $('#editUserForm input[name="address"]').val();
				var birthday = $('#editUserForm input[name="birthday"]').val();	
				
				$.ajax({ //通过后传到后台
					type: 'POST',
					url:  '${contextPath}/OnlineExam/editUser',
					data: {
						userId: userId,
						userName: userName,
						gender: gender,
						tel: tel,
						email: email,
						address: address,
						birthday: birthday,	
					},
					dataType: "json",
					success: function(data){
						//判断成功与否
						if(data.success){
							alert('修改成功');
							window.location.reload();
						}
					}
				});	
			//}
		});
			
			$(".delete-User").click(function() {
				var userId = $(this).parent().siblings().eq(1).text();
				$.ajax({
					type : 'POST',
					url : '${contextPath}/OnlineExam/delete',
					data : {
						userId : userId
					},
					dataType : "json",
					success: function(data){
						//判断成功与否
						if(data.success){
							alert('删除成功');
							window.location.reload();
						}
					}
				});	
			});
			
			$(".uploadFile-User").click(function(){
				$('#uploadFileModel').modal('show');	
			})
			
			
			//显示上传控制样式
			$('#uploadFile').ace_file_input({
				style:'well',
				btn_choose:'Drop files here or click to choose',
				btn_changse:null,
				on_icon:'ace-icon fa fa-cloud-upload',
				droppable:true,
				thumbnail:'small',
				preview_error: function(filename, error_code){
				}
			}).on('chang', function(){
				
			});
			
			//保存并导入Excel数据进行批量添加学生
		/* 	$('#uploadFileSaveBtn').on('click', function(){
				$.ajaxFileUpload({
					url: '${contextPath}/OnlineExam/uploadFile',
					secureuri:false,//一般设置为false
					fileElementId:'uploadFile',//文件上传控件的Id属性
					dataType:'json',
					complete: function(data){//只要完成执行,最后执行
						alert("保存上传执行完毕")
					},
					success:function (data, status){//服务器成功响应处理函数
						if(data.success){
							alert('成功');
						}else{
							alert(data.messageMap.message);
						}
					},
					error: function(data, status, e){//服务器响应失败处理函数
						alert(e);
					}			
				});
			}); */
			
			//批量保存
			$("#uploadFileSaveBtn").on('click',function(){
				$.ajaxFileUpload({
					url:'${contextPath}/OnlineExam/uploadFile',
					secureuri:false,
					fileElementId:'uploadFile',
					dataType:'json',
					complete:function(data){//只要完成即执行
						$('#batchAddModal').modal('hide');
					},
					success:function(data){
						if(data.success == "true"){
							alert("添加成功");
							window.location.reload();
						}else{
							alert(data.messageMap.message);
						}
					},
					error:function(data, status, e){
						alert("error:"+e);
					}
				});
			})	;
			</script>

		<!-- the following scripts are used in demo only for onpage help and you don't need them -->
		<link rel="stylesheet" href="${pageContext.request.contextPath}/static/assets/css/ace.onpage-help.css" />
		<link rel="stylesheet" href="${pageContext.request.contextPath}/static/docs/assets/js/themes/sunburst.css" />
		<script src="${pageContext.request.contextPath}/static/lib/ajaxfileupload.js"></script> 
		<script type="text/javascript"> ace.vars['base'] = '${pageContext.request.contextPath}/static'; </script>
		<script src="${pageContext.request.contextPath}/static/assets/js/ace/elements.onpage-help.js"></script>
		<script src="${pageContext.request.contextPath}/static/assets/js/ace/ace.onpage-help.js"></script>
		<script src="${pageContext.request.contextPath}/static/docs/assets/js/rainbow.js"></script>
		<script src="${pageContext.request.contextPath}/static/docs/assets/js/language/generic.js"></script>
		<script src="${pageContext.request.contextPath}/static/docs/assets/js/language/html.js"></script>
		<script src="${pageContext.request.contextPath}/static/docs/assets/js/language/css.js"></script>
		<script src="${pageContext.request.contextPath}/static/docs/assets/js/language/javascript.js"></script>
	</body>
</html>
